package GUI;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import sun.org.mozilla.javascript.internal.ast.Label;

import ControllerLayer.AddressCtr;

@SuppressWarnings("unused")
public class NewEmployeeUI {

	private AddressCtr addressCtr;
	private JFrame frame;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	
	private MainGUI mainGUI;

	/**
	 * Launch the application.
	 */


	/**
	 * Create the application.
	 */
	public NewEmployeeUI(MainGUI mainGUI) {
		this.mainGUI = mainGUI;
		addressCtr = AddressCtr.getInstance();
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 287, 380);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JButton button = new JButton("Annuller");
		button.setBounds(134, 276, 97, 25);
		button.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
			textField_1.setText("");
			textField_2.setText("");
			textField_3.setText("");
			textField_4.setText("");
			textField_5.setText("");
			frame.setVisible(false);
			}
		});
		frame.getContentPane().add(button);
		
		JButton btnOpret = new JButton("Opret");
		btnOpret.setBounds(27, 276, 97, 25);
		btnOpret.addActionListener(new ActionListener()
		{
		public void actionPerformed(ActionEvent E)
		{
			opretMedarbejder();
		}
		});
		
		frame.getContentPane().add(btnOpret);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(128, 127, 116, 22);
		frame.getContentPane().add(textField_1);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(10, 127, 116, 22);
		frame.getContentPane().add(lblPassword);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(128, 98, 116, 22);
		frame.getContentPane().add(textField_2);
		
		JLabel lblEmail = new JLabel("Email:");
		lblEmail.setBounds(10, 98, 114, 16);
		frame.getContentPane().add(lblEmail);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(128, 69, 116, 22);
		frame.getContentPane().add(textField_3);
		
		JLabel lblTelefon = new JLabel("Telefon:");
		lblTelefon.setBounds(10, 69, 114, 16);
		frame.getContentPane().add(lblTelefon);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(128, 40, 116, 22);
		frame.getContentPane().add(textField_4);
		
		JLabel lblAdresse = new JLabel("Adresse:");
		lblAdresse.setBounds(10, 40, 114, 16);
		frame.getContentPane().add(lblAdresse);
		
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		textField_5.setBounds(128, 11, 116, 22);
		frame.getContentPane().add(textField_5);
		
		JLabel lblNavn = new JLabel("Navn:");
		lblNavn.setBounds(10, 14, 114, 16);
		frame.getContentPane().add(lblNavn);
		

	}
	
	public void opretMedarbejder()
	{
		String name = textField_5.getText();
		String address = textField_4.getText();
		String tlf = textField_3.getText();
		String email = textField_2.getText();
		String password = textField_1.getText();
		if(name.length()<1 || address.length()<1 || tlf.length()<1 || email.length()<1 || password.length()<1)
		{
			JOptionPane.showMessageDialog(frame, "Alle felter skal udfyldes!", "Advarsel!", JOptionPane.ERROR_MESSAGE);
		}
		else{
			addressCtr.createEmployee(name, address, tlf, email, password);
			mainGUI.updateCustomerList();
			JOptionPane.showMessageDialog(frame, "Medarbejderen " + name + " er nu oprettet");
			textField_5.setText("");
			textField_4.setText("");
			textField_3.setText("");
			textField_2.setText("");
			textField_1.setText("");
			frame.setVisible(false);
		}

		}
	
	public void setVisible(boolean visible){
		frame.setVisible(visible);
	}
	
}
